package com.uchedao.seller.widget;

import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.uchedao.seller.R;

/**
 * 呼叫客服
 * Created by zhengxizhen on 15/10/27.
 */
public class CallServiceView extends LinearLayout {
    private Context mContext;

    private TextView tv_call_2;

    private String phone;

    public CallServiceView(Context context) {
        super(context);
        init(context);
    }

    public CallServiceView(Context context, AttributeSet attrs) {
        super(context, attrs);
        init(context);
    }

    public CallServiceView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        init(context);
    }

    private void init(Context context) {
        this.mContext = context;
        LayoutInflater.from(mContext).inflate(R.layout.custom_call_view, this);
        tv_call_2 = (TextView) findViewById(R.id.tv_call_2);
        findViewById(R.id.ll_call).setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                phone = TextUtils.isEmpty(phone) ? "4006500777" : phone;
                Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + phone));
                mContext.startActivity(intent);
            }
        });
    }

    public void setPhone(String phone) {
        this.phone = phone;
        tv_call_2.setText(phone);
    }
}
